$(document).ready(function(){
    $('button').click(function(){
        var id=$(this).attr('name');
        var ele = $(this);
        var hit =0;
        if(ele.attr("class") === 'add'){
            hit = +1;
        }
        else if(ele.attr("class") ==='less'){
            hit = -1;
        }
        $.ajax({
            url:'/car',
            type:'post',
            data:{id:$(this).attr('name'),'hit':hit},
            success:function(result){
                $('#counts').text(result.sum)
                ele.parent().find('input').val(result.counts)
                $('.sum').text('总计:'+(result.sub).toFixed(1)+'元')
                $('#'+id).text(result.check)
                if(result.counts <=0){
                     location.replace('/car')
                }
                if(result.sum <=0){
                    window.location.href='/shop';
                }
            },
            fail:function(result){
            }
        })
    });

})
